const STU_INFO = [ //学生数据数组
    [{ id: 1, name: `张三`, isStu: true, isLeader: false, desp: `` }, { id: 2, name: `李四`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 0, name: ``, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 3, name: `王五`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 36, name: `肖二`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 37, name: `丁一`, isStu: true, isLeader: false, isSp: true, desp: `重要程度：1` }],
    [{ id: 0, name: ``, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 4, name: `陆六`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 5, name: `唐七`, isStu: true, isLeader: true, isSp: false, desp: `` }, { id: 6, name: `朱八`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 7, name: `马零`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 8, name: `毛负`, isStu: true, isLeader: true, isSp: false, desp: `` }],
    [{ id: 9, name: `张一`, isStu: true, isLeader: false, isSp: true, desp: `重要程度：1` }, { id: 0, name: ``, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 10, name: `肖二`, isStu: true, isLeader: true, isSp: false, desp: `` }, { id: 11, name: `马三`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 12, name: `陆四`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 13, name: `唐五`, isStu: true, isLeader: false, isSp: false, desp: `` }],
    [{ id: 14, name: `朱六`, isStu: true, isLeader: false, isSp: false, desp: ``, desp: `` }, { id: 15, name: `宋七`, isStu: true, isLeader: true, isSp: false, desp: `` }, { id: 16, name: `魏八`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 17, name: `魏莱`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 18, name: `程诺`, isStu: true, isLeader: true, isSp: false, desp: `` }, { id: 19, name: `程波`, isStu: true, isLeader: false, isSp: false, desp: `` }],
    [{ id: 20, name: `宋青云`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 21, name: `周智若`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 22, name: `张无忌`, isStu: true, isLeader: false, isSp: true, desp: `重要程度：1` }, { id: 23, name: `易天行`, isStu: true, isLeader: true, isSp: false, desp: `` }, { id: 0, name: ``, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 0, name: ``, isStu: true, isLeader: false, isSp: false, desp: `` }],
    [{ id: 24, name: `秦浩`, isStu: true, isLeader: true, isSp: false, desp: `` }, { id: 25, name: `朱朝阳`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 26, name: `苗秀`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 27, name: `谭力`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 28, name: `项羽`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 29, name: `刘邦`, isStu: true, isLeader: false, isSp: false, desp: `` }],
    [{ id: 30, name: `宁财神`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 31, name: `祝无双`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 32, name: `燕小六`, isStu: true, isLeader: true, isSp: false, desp: `` }, { id: 33, name: `白展堂`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 34, name: `吕雉`, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 35, name: `佟湘玉`, isStu: true, isLeader: true, isSp: false, desp: `` }],
    [{ id: 0, name: ``, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 0, name: ``, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 0, name: ``, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: -1, name: `邹老师`, isStu: false, isLeader: false, isSp: false, desp: `` }, { id: 0, name: ``, isStu: true, isLeader: false, isSp: false, desp: `` }, { id: 0, name: ``, isStu: true, isLeader: false, isSp: false, desp: `` }]
];

function getRand(l, r) { //获取随机数的方法
    return Math.floor(Math.random() * (r - l + 1) + l);
}

function getStu() { //生成点名方法的工具方法
    let clickLock = 0; //闭包的共有变量，用来节流
    return function() { //点名的闭包方法
        if (clickLock) return; //节流
        this.selectNum = -2; //初始化选中的人
        clickLock = 1;
        const NUM = 10; //点名次数，即生成随机数的次数
        const DELAY = 400; //每次点名延迟
        let count = 0, //当前是第count次点名
            prev, cur = this.selectNum;
        const timeId = setInterval(() => { //这也是一个闭包
            if (count < NUM) {
                prev = cur;
                do {
                    cur = getRand(1, this.studentSize);
                } while (prev === cur); //为了视觉效果，避免点到和上一次一样人
                count++; //一次点名产生十次随机数
                this.selectNum = cur;
            } else {
                clearInterval(timeId);
                clickLock = 0; //释放节流阀
            }
        }, DELAY);
    }
}
const ROWS = 8; //表格的行数
const COLS = 6; //表格的列数

function tabReverse() { //镜像交换表格的方法
    let temp;
    //上下交换表格
    for (let i = 0; i < COLS; i++) {
        for (let j = 0; j < ROWS / 2; j++) {
            temp = this.students[j][i];
            this.students[j][i] = this.students[ROWS - j - 1][i];
            this.students[ROWS - j - 1][i] = temp;
        }
    }
    //左右交换表格
    this.students = this.students.map(ele => ele.reverse());
}

function show() {
    this.display = !this.display;
}

function link(index) {
    this.spCur = index;
}

function disLink() {
    this.spCur = -2;
}
const vm = new Vue({
    el: `#app`,
    data: {
        display: false, //用于显示下方的重点学生信息的数据,true是显示，false就隐藏
        selectNum: -2, //-2代表未选中
        studentSize: 37,
        students: STU_INFO,
        spCur: -2, //-2代表未选中
    },
    methods: {
        pickStu: getStu(), //调用工具方法生成点名的方法
        reverse: tabReverse, //反转表格的事件
        showOrNot: show,
        link,
        disLink
    }
})